package com.java.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java.dao.AdvertiserMapper;
import com.java.dao.ApplyMapper;
import com.java.model.Advertiser;
import com.java.model.Apply;
import com.java.model.Finance;
import com.java.model.Result;
import com.java.service.AdvertiserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AdvertiserServiceImpl implements AdvertiserService {

    @Autowired
    private AdvertiserMapper advertiserMapper;

    @Autowired
    private ApplyMapper applyMapper;

    @Override
    public PageInfo<Apply> applyList(Apply apply) {
        PageHelper.startPage(apply.getPageNum(), apply.getPageSize());
        apply.getAdsId();
        List<Apply> list = applyMapper.applyList2(apply);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<Apply> putList(Apply apply) {
        PageHelper.startPage(apply.getPageNum(), apply.getPageSize());
        apply.getAdsId();
        List<Apply> list = applyMapper.putList(apply);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<Apply> performanceList(Apply apply) {
        PageHelper.startPage(apply.getPageNum(), apply.getPageSize());
        apply.getAdsId();
        List<Apply> list = applyMapper.performanceList(apply);
        return new PageInfo<>(list);
    }

    @Override
    public Result yes(Apply apply) {
        applyMapper.yes(apply);
        applyMapper.deMany(apply);
        applyMapper.deMany2(apply);
        return Result.success();
    }

    @Override
    public PageInfo<Advertiser> list(Advertiser advertiser) {
        PageHelper.startPage(advertiser.getPageNum(), advertiser.getPageSize());
        List<Advertiser> list =  advertiserMapper.list(advertiser);
        return new PageInfo<>(list);
    }

    @Override
    public Advertiser detail(Advertiser advertiser) {
        return  advertiser;
    }

    @Override
    public Advertiser get(int id) {
        return advertiserMapper.get(id);
    }

    @Transactional
    @Override
    public void remove(int[] ids) {
        for (int id : ids){
            advertiserMapper.remove(id);
        }
    }

    @Override
    public PageInfo<Finance> fList(Finance finance) {
        PageHelper.startPage(finance.getPageNum(), finance.getPageSize());
        List<Finance> list =  advertiserMapper.fList(finance);
        return new PageInfo<>(list);
    }

    @Override
    public Advertiser fDetail(Advertiser advertiser) {
        return advertiser;
    }

    /**
     * 广告主数量总数
     * @return
     */
    @Override
    public List<Advertiser> advertisersCount() {
        return advertiserMapper.advertisersCount();
    }


}
